<!DOCTYPE html>
<!-- saved from url=(0052)http://49.233.183.177:8080/addressbook/register.html -->
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">


    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>注册</title>

    <!-- Custom fonts for this template-->
    <link rel="stylesheet" href="plugin/layui/css/layui.css"/>
    <!-- Custom styles for this template-->
    <link href="css/sb-admin-2.min.css" rel="stylesheet">

</head>

<body class="bg-gradient-primary">

<div class="container">

    <div class="card o-hidden border-0 shadow-lg my-5">
        <div class="card-body p-0">
            <!-- Nested Row within Card Body -->
            <div class="row">
                <div class="col-lg-5 d-none d-lg-block bg-register-image"></div>
                <div class="col-lg-7">
                    <div class="p-5">
                        <div class="text-center">
                            <h1 class="h4 text-gray-900 mb-4">创建账号!</h1>
                        </div>
                        <form class="user">
                            <div class="form-group">
                                <input type="text" class="form-control form-control-user" id="name"
                                       name="name" placeholder="昵称">
                            </div>
                            <div class="form-group" style="position: relative;">
                                <input type="email" class="form-control form-control-user" id="email"
                                       name="email" placeholder="邮箱">
                                <button style="position: absolute;right: 10px;top: 7px;" class="layui-btn layui-btn-radius layui-btn-normal" type="button">发送验证码</button>
                            </div>
                            <div class="form-group">
                                <input type="password" class="form-control form-control-user" id="password"
                                       name="password" placeholder="注册密码">
                            </div>
                            <div class="form-group">
                                <input type="text" class="form-control form-control-user" id="checkcode"
                                       name="checkcode" placeholder="验证码">
                            </div>
                            <font color="red"></font>
                            <button type="button" class="btn btn-primary btn-user btn-block" id="registsubmit">注册
                            </button>
                            <hr>
                        </form>
                        <hr>
                        <div class="text-center">
                            <a class="small" href="login.html">已有账号? 登录!</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
</body>
<script src="plugin/jquery/jquery-3.3.1.min.js"></script>
<script src="plugin/util.js"></script>
<script src="plugin/layui/layui.js"></script>
<script>
$(function () {
    layui.use('layer', function () {
        var layer = layui.layer;
    });


    $("#registsubmit").click(function () {

        let flag = false;
        $(".user .form-group>input").each(function () {
            if ( $.emptyString($(this).val()) ){
                flag = true;
                layer.alert($(this).attr("placeholder")+"未填写",{icon:5})
                return false;
            }
        })
        //是否有框未填写
        if (flag){
            return;
        }
        $.post("user/register", $(".user").serialize(), function (data) {
            //成功
            if (!data.error){
                layer.msg(data.message,{icon:1,time:1000})
                setTimeout(function () {
                    location.href = "login.html";
                },1000)
            } else{
                layer.alert(data.message,{icon:5})
            }
        })
    })
})
</script>
</html>